import { DrgInqApi } from "@/api/pharMgmt/drgInq";
import { BasicDrawer, useDrawerInner } from "@/components/Drawer";
import { BasicColumn, BasicTable, FormSchema, useTable } from "@/components/Table";
import { Tag } from "antd";
import { useTranslation } from "react-i18next";
const newAdd = (props: any) => {
	const en_vi = "drugStorage";
	const { t } = useTranslation();
	const [registerDrawer, { closeDrawer }] = useDrawerInner(props.register, data => {
		console.log("data>>>>>>>>>>>>>>>", data);
	});
	const schemas: FormSchema[] = [
		{
			label: t(`${en_vi}.inventoryManagement.drugInventory.drugName`),
			field: "drugName",
			component: "Input"
		}
	];
	const columns: BasicColumn[] = [
		{
			title: t("felix_ui.barCode"),
			dataIndex: "barCode"
		},
		{
			title: t(`${en_vi}.inventoryManagement.drugInventory.drugName`),
			dataIndex: "drugName"
		},
		{
			title: t("felix_ui.drugSpec"),
			dataIndex: "drugSpec"
		},
		{
			title: t("felix_ui.storageCond"),
			dataIndex: "storageCond"
		},
		{
			title: t("felix_ui.drugAds"),
			dataIndex: "drugAds"
		},
		{
			title: t("felix_ui.dosePerTime"),
			dataIndex: "dosePerTime"
		},
		{
			title: t("felix_ui.timesPerDay"),
			dataIndex: "timesPerDay"
		},
		{
			title: t("felix_ui.sideEffects"),
			dataIndex: "sideEffects"
		},
		{
			title: t("felix_ui.weight"),
			dataIndex: "weight"
		},
		{
			title: t("felix_ui.activeIngre"),
			dataIndex: "activeIngre"
		},
		{
			title: t(`${en_vi}.drugManagement.drugInfo.drugCats`),
			dataIndex: "categoryName"
		},
		{
			title: t("felix_ui.unitId"),
			dataIndex: "unitId"
		},
		{
			title: t("felix_ui.purPrice"),
			dataIndex: "purPrice"
		},
		{
			title: t("felix_ui.salePrice"),
			dataIndex: "salePrice"
		},
		{
			title: t("felix_ui.minPrice"),
			dataIndex: "minPrice"
		},
		{
			title: t("felix_ui.status"),
			dataIndex: "status",
			render: (_, { status }) => (
				<>
					{status == "0" ? (
						<Tag color="success">{t(`${en_vi}.inventoryManagement.warehouseInformation.open`)}</Tag>
					) : (
						<Tag color="error">{t(`${en_vi}.inventoryManagement.warehouseInformation.close`)}</Tag>
					)}
				</>
			)
		}
	];
	const [registerTable, { getSelectRows }] = useTable({
		api: DrgInqApi.getDrgInqPage,
		columns,
		rowSelection: true,
		formConfig: {
			labelWidth: 150,
			schemas,
			showActionButtonGroup: true,
			showAdvancedButton: false,
			baseColProps: { span: 12 },
			actionColOptions: { span: 24 }
		},
		bordered: true,
		useSearchForm: true
	});
	const handleSubmit = async () => {
		const item = getSelectRows();
		props.setDrugId(item[0]?.drugId);
		closeDrawer();
	};
	return (
		<BasicDrawer
			size="large"
			{...props}
			title={t("drugStorage.selectPurchaseOrder")}
			register={registerDrawer}
			ok={handleSubmit}
			showFooter={true}
		>
			<BasicTable register={registerTable}></BasicTable>
		</BasicDrawer>
	);
};
export default newAdd;
